﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="fie_seisundType_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(FieSeisundTypeV4))]
    public class FieSeisundTypeV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IFieSeisundTypeV4 clazz;
        
        public FieSeisundTypeV4Serializer(IFieSeisundTypeV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tegevus");
            if (clazz.Tegevus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tegevus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("elemtyyp");
            if (clazz.Elemtyyp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Elemtyyp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Elemtyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("alguskpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Alguskpv))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("loppkpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Loppkpv))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("periood");
            if (clazz.Periood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Periood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Periood");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tegevus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fie_seisundType_v4>tegevus");
                }
                clazz.Tegevus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegevus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fie_seisundType_v4>tegevus", Reader.LocalName);
            }
            if (Reader.LocalName=="elemtyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fie_seisundType_v4>elemtyyp");
                }
                clazz.Elemtyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("elemtyyp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fie_seisundType_v4>elemtyyp", Reader.LocalName);
            }
            if (Reader.LocalName=="alguskpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fie_seisundType_v4>alguskpv");
                }
                clazz.Alguskpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("alguskpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fie_seisundType_v4>alguskpv", Reader.LocalName);
            }
            if (Reader.LocalName=="loppkpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fie_seisundType_v4>loppkpv");
                }
                clazz.Loppkpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("loppkpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fie_seisundType_v4>loppkpv", Reader.LocalName);
            }
            if (Reader.LocalName=="periood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fie_seisundType_v4>periood");
                }
                clazz.Periood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("periood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fie_seisundType_v4>periood", Reader.LocalName);
            }
        }
    }
}
